/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
// 非递归，使用栈迭代
func inorderTraversal(root *TreeNode) (res []int) {
	var s []*TreeNode
	for root != nil || len(s) > 0 {
		for root != nil {
			s = append(s, root)
			root = root.Left
		}

		root = s[len(s)-1]
		s = s[:len(s)-1]
		res = append(res, root.Val)
		root = root.Right
	}

	return
}